package com.community.backend.service.impl;

import com.community.backend.mapper.InteractionMapper;
import com.community.backend.pojo.Interaction;
import com.community.backend.pojo.dto.InteractionQueryDTO;
import com.community.backend.service.InteractionService;
import com.community.backend.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

@Service
public class InteractionServiceImpl implements InteractionService {
    private final InteractionMapper interactionMapper;

    public InteractionServiceImpl(InteractionMapper interactionMapper) {
        this.interactionMapper = interactionMapper;
    }

    @Override
    public PageResult pageQuery(InteractionQueryDTO interactionQueryDTO) {
        PageHelper.startPage(interactionQueryDTO.getCurrentPage(),interactionQueryDTO.getPageSize());
        Page<Interaction> page = interactionMapper.pageQuery(interactionQueryDTO);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Interaction interaction) {
        interaction.setDeleted(0);//逻辑删除
        interactionMapper.add(interaction);
    }

    @Override
    public void deleteById(Integer id) {
        interactionMapper.deleteById(id);
    }

    @Override
    public void update(Interaction interaction) {
        interactionMapper.update(interaction);
    }
}
